#include "StdAfx.h"
#include "MAPITable.h"


#define INITGUID
#define USES_IID_IMAPITable
#include <initguid.h>
#include <mapiguid.h>


CMAPITable::CMAPITable( LPINNEROBJ_T pObj ) : m_pObj( pObj ), m_cRef( 1 )
{
	static char * szFun = "CMAPITable::CMAPITable";
	LogEntry(szFun);

	if ( m_pObj ) {
		m_pObj->AddRef();
	}
}


CMAPITable::~CMAPITable(void)
{
	static char * szFun = "CMAPITable::~CMAPITable";
	LogEntry(szFun);

	if ( m_pObj ) {
		m_pObj->Release();
	}
}


//////////////////////////////////////////////////////////////////////////
// Implementation IUnknown
STDMETHODIMP CMAPITable::QueryInterface (REFIID riid, LPVOID * ppvObj)
{
	static char * szFun = "CMAPITable::QueryInterface";
	LogEntry(szFun);

	*ppvObj = NULL;

	if ( riid == IID_IMAPITable ||
		riid == IID_IUnknown ) {
			*ppvObj = (LPVOID)this;
			AddRef();
			return S_OK;
	} else {
		*ppvObj = NULL;
		return E_NOINTERFACE;
	}
}


STDMETHODIMP_(ULONG) CMAPITable::AddRef ()
{
	static char * szFun = "CMAPITable::AddRef";
	LogEntry(szFun);
	if ( !m_pObj ) {
		return NULL;
	}

	++m_cRef;
	return m_cRef;
}


STDMETHODIMP_(ULONG) CMAPITable::Release ()
{
	static char * szFun = "CMAPITable::Release";
	LogEntry(szFun);
	if (!m_pObj) {
		return NULL;
	}

	--m_cRef;
	if (m_cRef == 0) {
		delete this;
		return 0;
	}

	return m_cRef;
}


//////////////////////////////////////////////////////////////////////////
// Implementation  IMAPITable
HRESULT CMAPITable::Abort( void )
{
	static char * szFun = "CMAPITable::Abort";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if ( m_pObj ) {
		hRes = m_pObj->Abort( );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::Advise(
						   ULONG ulEventMask,
						   LPMAPIADVISESINK lpAdviseSink,
						   ULONG FAR * lpulConnection
						   )
{
	static char * szFun = "CMAPITable::Advise";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->Advise(
			ulEventMask,
			lpAdviseSink,
			lpulConnection );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::CollapseRow(
								ULONG cbInstanceKey,
								LPBYTE pbInstanceKey,
								ULONG ulFlags,
								ULONG FAR * lpulRowCount
								)
{
	static char * szFun = "CMAPITable::CollapseRow";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->CollapseRow(
			cbInstanceKey,
			pbInstanceKey,
			ulFlags,
			lpulRowCount );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::CreateBookmark(
								   BOOKMARK FAR * lpbkPosition
								   )
{
	static char * szFun = "CMAPITable::CreateBookmark";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->CreateBookmark(
			lpbkPosition );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::ExpandRow(
							  ULONG cbInstanceKey,
							  LPBYTE pbInstanceKey,
							  ULONG ulRowCount,
							  ULONG ulFlags,
							  LPSRowSet FAR * lppRows,
							  ULONG FAR * lpulMoreRows
							  )
{
	static char * szFun = "CMAPITable::ExpandRow";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->ExpandRow(
			cbInstanceKey,
			pbInstanceKey,
			ulRowCount,
			ulFlags,
			lppRows,
			lpulMoreRows );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::FindRow(
							LPSRestriction lpRestriction,
							BOOKMARK BkOrigin,
							ULONG ulFlags
							)
{
	static char * szFun = "CMAPITable::FindRow";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->FindRow(
			lpRestriction,
			BkOrigin,
			ulFlags );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::FreeBookmark(
								 BOOKMARK bkPosition
								 )
{
	static char * szFun = "CMAPITable::FreeBookmark";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->FreeBookmark( bkPosition );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::GetCollapseState(
									 ULONG ulFlags,
									 ULONG cbInstanceKey,
									 LPBYTE lpbInstanceKey,
									 ULONG FAR * lpcbCollapseState,
									 LPBYTE FAR * lppbCollapseState
									 )
{
	static char * szFun = "CMAPITable::GetCollapseState";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->GetCollapseState(
			ulFlags,
			cbInstanceKey,
			lpbInstanceKey,
			lpcbCollapseState,
			lppbCollapseState );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::GetLastError(
								 HRESULT hResult,
								 ULONG ulFlags,
								 LPMAPIERROR FAR * lppMAPIError
								 )
{
	static char * szFun = "CMAPITable::GetLastError";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->GetLastError(
			hResult,
			ulFlags,
			lppMAPIError );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::GetRowCount(
								ULONG ulFlags,
								ULONG FAR * lpulCount
								)
{
	static char * szFun = "CMAPITable::GetRowCount";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->GetRowCount(
			ulFlags,
			lpulCount );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::GetStatus(
							  ULONG FAR * lpulTableStatus,
							  ULONG FAR * lpulTableType
							  )
{
	static char * szFun = "CMAPITable::GetStatus";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->GetStatus(
			lpulTableStatus,
			lpulTableType );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::QueryColumns(
								 ULONG ulFlags,
								 LPSPropTagArray FAR * lpPropTagArray
								 )
{
	static char * szFun = "CMAPITable::QueryColumns";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->QueryColumns(
			ulFlags,
			lpPropTagArray );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::QueryPosition(
								  ULONG FAR * lpulRow,
								  ULONG FAR * lpulNumerator,
								  ULONG FAR * lpulDenominator
								  )
{
	static char * szFun = "CMAPITable::QueryPosition";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->QueryPosition(
			lpulRow,
			lpulNumerator,
			lpulDenominator );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::QueryRows(
							  LONG lRowCount,
							  ULONG ulFlags,
							  LPSRowSet FAR * lppRows
							  )
{
	static char * szFun = "CMAPITable::QueryRows";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->QueryRows(
			lRowCount,
			ulFlags,
			lppRows );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::QuerySortOrder(
								   LPSSortOrderSet FAR * lppSortCriteria
								   )
{
	static char * szFun = "CMAPITable::QuerySortOrder";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->QuerySortOrder( lppSortCriteria );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::Restrict(
							 LPSRestriction lpRestriction,
							 ULONG ulFlags
							 )
{
	static char * szFun = "CMAPITable::Restrict";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->Restrict(
			lpRestriction,
			ulFlags );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::SeekRow(
							BOOKMARK bkOrigin,
							LONG lRowCount,
							LONG FAR * lplRowsSought
							)
{
	static char * szFun = "CMAPITable::SeekRow";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->SeekRow(
			bkOrigin,
			lRowCount,
			lplRowsSought );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::SeekRowApprox(
								  ULONG ulNumerator,
								  ULONG ulDenominator
								  )
{
	static char * szFun = "CMAPITable::SeekRowApprox";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->SeekRowApprox(
			ulNumerator,
			ulDenominator );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::SetCollapseState(
									 ULONG ulFlags,
									 ULONG cbCollapseState,
									 LPBYTE pbCollapseState,
									 BOOKMARK FAR * lpbkLocation
									 )
{
	static char * szFun = "CMAPITable::SetCollapseState";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->SetCollapseState(
			ulFlags,
			cbCollapseState,
			pbCollapseState,
			lpbkLocation );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::SetColumns(
							   LPSPropTagArray lpPropTagArray,
							   ULONG ulFlags
							   )
{
	static char * szFun = "CMAPITable::SetColumns";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->SetColumns(
			lpPropTagArray,
			ulFlags );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::SortTable(
							  LPSSortOrderSet lpSortCriteria,
							  ULONG ulFlags
							  )
{
	static char * szFun = "CMAPITable::SortTable";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT/*MAPI_E_NO_SUPPORT*/;

 	if (  m_pObj ) {
 		hRes = m_pObj->SortTable(
 			lpSortCriteria,
 			ulFlags );
 	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::Unadvise(
							 ULONG ulConnection
							 )
{
	static char * szFun = "CMAPITable::Unadvise";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->Unadvise( ulConnection );
	}

	LogReturn(szFun, hRes);
	return hRes;
}


HRESULT CMAPITable::WaitForCompletion(
									  ULONG ulFlags,
									  ULONG ulTimeout,
									  ULONG FAR * lpulTableStatus
									  )
{
	static char * szFun = "CMAPITable::WaitForCompletion";
	LogEntry(szFun);

	HRESULT hRes = MAPI_E_NO_SUPPORT;

	if (  m_pObj ) {
		hRes = m_pObj->WaitForCompletion(
			ulFlags,
			ulTimeout,
			lpulTableStatus );
	}

	LogReturn(szFun, hRes);
	return hRes;
}
